<template>
	<div>
		<el-form ref="form" :model="form" :rules="rules"  label-width="80px">
			<el-form-item label="姓名" prop="workerName">
				<el-input v-model="form.workerName"></el-input>
			</el-form-item>
			
			<el-form-item label="性别" prop="workerGender">
				<el-select v-model="form.workerGender" placeholder="请选择..">
					<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
			</el-form-item>

			<el-form-item label="年龄" prop="workerAge">
				<el-input v-model="form.workerAge"></el-input>
			</el-form-item>

			<el-form-item label="员工号" prop="staffId">
				<el-input v-model="form.staffId"></el-input>
			</el-form-item>

			<el-form-item label="员工类别">
				<el-input v-model="form.workerCategory"></el-input>
			</el-form-item>

			<el-form-item label="入职时间" prop="entryTime">
				<el-date-picker value-format="yyyy-MM-dd" type="date" v-model="form.entryTime" placeholder="选择日期">
				</el-date-picker>
			</el-form-item>

			<el-form-item label="操作人">
				<el-input v-model="form.operator"></el-input>
			</el-form-item>

			<el-form-item label="操作时间" prop="operatorTime">
				<el-date-picker value-format="yyyy-MM-dd" type="date" v-model="form.operatorTime" placeholder="选择日期">
				</el-date-picker>
			</el-form-item>

			<el-form-item label="职务">
				<el-input v-model="form.post"></el-input>
			</el-form-item>

			<el-form-item label="职称">
				<el-input v-model="form.title"></el-input>
			</el-form-item>

			<el-form-item label="人员状态">
				<el-input v-model="form.workerState"></el-input>
			</el-form-item>

			<el-form-item label="简介">
				<el-input v-model="form.introduction"></el-input>
			</el-form-item>

			<el-form-item label="备注">
				<el-input v-model="form.remarks"></el-input>
			</el-form-item>

			<el-form-item>
				<el-button type="primary" plain @click="save">保存数据</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	import axios from '@/utils/axiosutils.js';
	export default {
		name: 'StaffAdd',
		props: ['editid'],
		components: {},
		data() {
			return {
				form: {
					workerName: '',
					workerGender: '',
					workerAge: '',
					staffId: '',
					workerCategory: '',
					entryTime: '',
					operator: '',
					operatorTime: '',
					post: '',
					titl: '',
					workerState: '',
					introduction: '',
					remarks: ''
				},
				rules:{
					workerName:[{required: true, message: '请输入', trigger: 'blur'}],
					workerGender:[{required: true, message: '请输入', trigger: 'blur'}],
					workerAge:[{required: true, message: '请输入', trigger: 'blur'}],
					staffId:[{required: true, message: '请输入', trigger: 'blur'}],
					entryTime:[{required: true, message: '请输入', trigger: 'blur'}],
					operatorTime:[{required: true, message: '请输入', trigger: 'blur'}],
				},
				isupdate: false,
				 options: [{
				          value: '男',
				          label: '男'
				        }, {
				          value: '女',
				          label: '女'
				        }]
			};
		},
		created() {
			if (this.editid) {
				// 如果是修改 用户名输入框禁用
				this.isupdate = true;
				axios.get(
					'/worker/getById',
					response => {
						this.form.workerId = this.editid;
						this.form.workerName = response.obj.workerName;
						this.form.workerGender = response.obj.workerGender;
						this.form.workerAge = response.obj.workerAge;
						this.form.staffId = response.obj.staffId;
						this.form.workerCategory = response.obj.workerCategory;
						this.form.entryTime = response.obj.entryTime;
						this.form.operator = response.obj.operator;
						this.form.operatorTime = response.obj.operatorTime;
						this.form.post = response.obj.post;
						this.form.titl = response.obj.titl;
						this.form.workerState = response.obj.workerState;
						this.form.introduction = response.obj.introduction;
						this.form.remarks = response.obj.remarks;
					}, {
						workerId: this.editid
					}
				);
			}
		},
		methods: {
			save: function() {
				axios.post(
					'/worker/add',
					resp => {
						this.$emit('update:show', false);
						this.$emit('getData');
					},
					this.form
				);
			}
		}
	};
</script>

<style></style>
